package com.hh.core.config;

import net.sf.ehcache.CacheManager;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

/**
 * 
* @ClassName: EhCacheConfig  
* @Description: TODO(EhCache 配置)  
* @author hxn
* @date 2018年1月15日 下午3:33:32  
*
 */
@Configuration
@EnableCaching
public class EhCacheConfig {

	@Value("${ehcache.path}")  
	private String ehcachePath;
	
	/**
	 * 
	* @Title: ehcache  
	* @Description:   设置加载ehcache路径
	* @param @return    设定文件  
	* @return EhCacheManagerFactoryBean    返回类型  
	* @author hxn
	* @date 2018年1月15日 下午3:34:06  
	* @throws
	 */
	@Bean
    public EhCacheManagerFactoryBean ehcache() {
        EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
        ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource(ehcachePath));
        return ehCacheManagerFactoryBean;
    }
	
	/**
	 * 
	* @Title: cacheManager  
	* @Description:   cacheManager 注入spring
	* @param @param cacheManager
	* @param @return    设定文件  
	* @return EhCacheCacheManager    返回类型  
	* @author hxn
	* @date 2018年1月15日 下午3:34:37  
	* @throws
	 */
    @Bean
    public EhCacheCacheManager cacheManager(CacheManager cacheManager) {
        return new EhCacheCacheManager(cacheManager);
    }
}
